package com.aabte.spring.annotation.config;

import com.aabte.spring.beans.Person;
import com.aabte.spring.condition.LinuxCondition;
import com.aabte.spring.condition.WindowsCondition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * 根据系统类型，注入Person对象
 *
 * @author Daniel
 */
@Configuration
public class ConditionalConfig {

    @Conditional(value = {WindowsCondition.class})
    @Bean("bill")
    public Person bill() {
        return Person.builder()
                .name("Bill Gates")
                .age(64)
                .build();
    }

    @Conditional(value = {LinuxCondition.class})
    @Bean("linux")
    public Person linus() {
        return Person.builder()
                .name("linus")
                .age(52)
                .build();
    }

}
